<template>
  <transition name="confirm-fade">
    <div class="confirm" v-show="isShow" @click.stop>
      <div class="confirm-wrapper">
          <div class="confirm-content">
              <p class="text">{{text}}</p>
              <div class="operate">
                <div class="operate-btn left" @click="cancle">{{cancleBtnText}}</div>
                <div class="operate-btn" @click="confirm">{{confirmBtnText}}</div>
              </div>
          </div>
      </div>
    </div>
  </transition>
</template>
<script>
export default {
  name: 'Confirm',
  props: {
    text: {
      type: String,
      default: ''
    },
    confirmBtnText: {
      type: String,
      default: '确定'
    },
    cancleBtnText: {
      type: String,
      default: '取消'
    }
  },
  data () {
    return {
      isShow: false
    }
  },
  methods: {
    cancle () {
      this.hide()
      this.$emit('cancle')
    },
    confirm () {
      this.hide()
      this.$emit('confirm')
    },
    show () {
      this.isShow = true
    },
    hide () {
      this.isShow = false
    }
  }
}
</script>
<style lang="scss" scoped>
@import 'common/scss/variable.scss';
.confirm{
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 998;
  background: $color-background-d;
  .confirm-wrapper{
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    z-index: 999;
    .confirm-content{
      width: 5.4rem;
      border-radius: 0.26rem;
      background: $color-highlight-background;
      animation: confirm-zoom 0.3s;
      .text{
        padding: 0.38rem 0.3rem;
        line-height: 0.44rem;
        text-align: center;
        font-size: $font-size-large;
        color: $color-text-l;
      }
      .operate{
        display: flex;
        align-items: center;
        text-align: center;
        font-size: $font-size-large;
        .operate-btn{
          flex: 1;
          line-height: 0.44rem;
          padding: 0.2rem 0;
          border-top: 1px solid $color-background-d;
          color: $color-text-d;
          &.left{
            border-right: 1px solid $color-background-d;
          }
        }
      }
    }
  }
}
.confirm-fade-enter-active{
  animation: confirm-fadeIn 0.3s;
}
@keyframes fadeIn {
  from{
    opacity: 0;
  }
  to{
    opacity: 1;
  }
}
@keyframes confirm-zoom {
  0%{
    transform: scale(0)
  }
  60%{
    transform: scale(1.1)
  }
  100%{
    transform: scale(1.0)
  }
}
</style>
